package bobochat.mapper;

import bobochat.entity.FriendRequest;
import bobochat.entity.MyFriends;
import bobochat.entity.Users;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author shkstart
 * @create 2019-11-08 21:30
 */
@Mapper
public interface UsersMapper {


    /**
     * 查询数据库中所有的用户信息
     * @return
     */

    @Select("select * from users")
    List<Users> selectAllUsers();

    @Insert("insert into users(id,username,password,face_image,face_image_big,qrcode) " +
            "values(#{id},#{username},#{password},#(faceImage),#{faceImageBig},#{qrcode}")
    void addUser(Users user);


    @Select("select * from users where username=#{username}  and  password=#{password}  ")
    Users selectUsersByUsernameAndPassword(Users users);

    @Select("select * from users where username=#{username}")
    Users selectUserByUsername(String username);


    @Update("update users set nickname=#{nickname} where id=#{id}")
    int updateUsersNicknameByUsersid(Users users);

    @Update("update users set face_image=#{faceImage} where id=#{id}") //#{?}   column
    int updateUsersFaceImageById(Users users);

    @Update("update users set password=#{newPassword} where id=#{id} and password=#{oldPassword}")
    int updateUsersPasswordByUsersidAndPassword(@Param("newPassword")String newPassword,@Param("id") String id, @Param("oldPassword")String oldPassword);


    @Select("select * from users where id = #{id}")
    Users selectUsersById(String id);

    @Select("select * from friend_request where accept_user_id  = #{userId}")
    FriendRequest selsectFriendRuqestById(String id);

    @Insert("insert into friends_request(id,send_user_id,accept_user_id,request_date_time) " +
            "values(#{id},#{sendUserId},#{acceptUserId},#{sendRequestDateTime})")
    void addFriendRequest(FriendRequest friendRequest);

    @Delete("delete * from friendsRequest where id=#{id}")
    void deleteRequestByid(FriendRequest friendRequest);

    @Insert("insert into my_friends(id,my_user_id,my_friend_user_id) " +
            "values(#{id},#{myUserId},#{myFriendsUserId})")
    void addFriends(MyFriends myFriends);

}